package com.bjsxt.service;

import java.io.FileNotFoundException;
import java.io.IOException;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.bjsxt.dao.UserDAO;
import com.bjsxt.model.User;

@Component("userService")
public class UserService
{

	private UserDAO userDAO;

	public void init()
	{
		System.out.println("init");
	}

	public void add(User user) throws FileNotFoundException, IOException
	{
		userDAO.save(user);
		
//		As Interceptor doesn't cover this package, so "@AfterThrowing" can't catch the exception written in this class
		
//		File file = new File("C:/a.a.a.a");
//		BufferedReader br;
//		br = new BufferedReader(new FileReader(file));
//		StringBuilder content = new StringBuilder();
//		char[] buffer = new char[4096];
//		int len;
//		while ((len = br.read(buffer)) > 0)
//		{
//			content.append(buffer, 0, len);
//		}

	}

	public UserDAO getUserDAO()
	{
		return userDAO;
	}

	@Resource(name = "u")
	public void setUserDAO(UserDAO userDAO)
	{
		this.userDAO = userDAO;
	}

	public void destroy()
	{
		System.out.println("destroy");
	}

	// public static void main(String[] args)
	// {
	// new UserService().add(new User());
	// }
}
